package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.ht.medicaltreatment.bean.BorrowPage
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class BorrowViewModel : BaseViewModel() {
    fun request(currentPage :Int,status:Int,orderName:String,sampleName:String,projcetId:String,startTime:String,endTime:String,
                onSuccess:(MutableList<BorrowPage>?)->Unit){
        viewModelScope.launch{
            val bean = mApi.borrowList(currentPage,50,status,orderName,sampleName,projcetId,startTime,endTime)
            when(bean){
                is ApiResult.Success -> {
                    onSuccess(bean.data.data?.pageList)
                }
                is ApiResult.Error -> {
                    dismissProgress(bean.errorMessage)
                }
            }
        }
    }

    fun delete(orderId:MutableList<String>,onSuccess: () -> Unit){
        viewModelScope.launch{
            val bean = mApi.deleteBorrowOrder(orderId)
            when(bean){
                is ApiResult.Success -> {
                    onSuccess()
                }
                is ApiResult.Error -> {
                    dismissProgress(bean.errorMessage)
                }
            }
        }
    }
}